package edu.jmu.restful;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.stereotype.Repository;

@Repository
public class UserDaoHashMapImpl implements UserDao {
	private static HashMap<Integer, User> users = new HashMap<>();
	
	
	static{
		for (int i = 0; i < 3; i++) {
			User user = new User();
			user.setUserid(i);
			user.setUsername("name"+i);
			user.setPassword(user.getUsername());
			users.put(i, user);
		}
	}
	
	@Override
	public int addUser(User user) {
		if(users.containsKey(user.getUserid()))
			return -1;
			
		users.put(user.getUserid(), user);
		return 1;
		
	}

	@Override
	public int updateUser(User user) {
		if(!users.containsKey(user.getUserid()))
			return -1;
		users.put(user.getUserid(), user);
		return 0;
	}

	@Override
	public int deleteUserById(int id) {
		if(!users.containsKey(id))
			return -1;
		
		users.remove(id);
		return 1;
	}

	@Override
	public User findUserById(int id) {
		
		return users.get(id);
	}

	@Override
	public User findUserByIdRowMapper(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<User> findAllUser() {
		List<User> userList = new ArrayList<>();
		userList.addAll(users.values());
		return userList;
	}

	@Override
	public User findUserByIdCallbackHandler(int id) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public List<User> findAllUserCallbackHandler() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int countAll() {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public void otherTest() {
		// TODO Auto-generated method stub
		
	}
	
	

	

}
